This file is a part of the Open Science Framework repository at https://osf.io/djkyf/. A rendered version of this R Markdown file is normally available at this GitHub HTML Preview service page.
Note that in that preview, the ‘tabbed layout’ that makes, for example, userfriendly inspection of the pairwise scatterplots possible, does not work (perhaps GitHub Preview blocks javascript?), so you may want to download the rendered .html in any case.
### Import using haven
dat <-
haven::read_sav(file.path(dataPath,
'database.orig.new labels.sav'));
### ... But convert to a data frame instead of a tibble, because,
### for example, length(unique(dat[, 'group'])) results in 1 instead
### of 2...
dat <- as.data.frame(dat);
dat <- haven::zap_label(dat);
dat <- haven::zap_labels(dat);
### Set group as factor
dat$group <-
factor(dat$group,
levels=1:2,
labels=c("Alternative medicine",
"Medicine"));
dat$group_tri <-
ifelse(dat$group=="Medicine",
1,
ifelse(dat$TCM6_simult < 3,
2,
ifelse(dat$TCM6_simult > 2,
3,
NA)));
dat$group_tri <-
factor(dat$group_tri,
levels=1:3,
labels=c("Biomed",
"Alternative",
"Complementary"));
### Extract and store attitude variable names
attitudeVars <-
grep('ATT1_',
names(dat),
value=TRUE);
attitudeVars_2 <-
grep('ATT2_',
names(dat),
value=TRUE);
constructTreeYAML <-
yum::load_yaml_fragments(here::here("methods-construct-tree",
"cam-biomed-attitude-tree-1.dct"));
constructTree <-
yum::build_tree(constructTreeYAML);
constructTree$Do(function(node) {
nameFromDataset <-
grep(node$name,
names(dat),
value=TRUE);
print(nameFromDataset);
if (length(nameFromDataset) > 0) {
node$label <- nameFromDataset;
}},
filterFun = data.tree::isLeaf);
## [1] "ATT1_4_BodyMirrorToSoul"
## [1] "ATT1_31_IllnessSymbology"
## [1] "ATT1_21_IllnessBecauseOfEmotions"
## [1] "ATT1_33_SymptomsWillDisappear"
## [1] "ATT1_9_MindHasStrongEffect"
## [1] "ATT1_11_BodyRemembers"
## [1] "ATT1_36_UnprocessedTrauma"
## [1] "ATT1_28_ConfrontingEmotionalProb"
## [1] "ATT1_26_HealingResultOfEmoDevelopment"
## [1] "ATT1_18_TreatsOnlySymptoms"
## [1] "ATT1_17_SickByChance"
## [1] "ATT1_20_HealingIsLuck"
## [1] "ATT1_10_AttractPplAndEvents"
## [1] "ATT1_16_EverythingConnected"
## [1] "ATT1_23_NothingByChance"
## [1] "ATT1_2_MustSuffer"
## [1] "ATT1_38_IllnessTeachesUs"
## [1] "ATT1_34_EnergyInEastern"
## [1] "ATT1_27_EnergeticSystemInBody"
## [1] "ATT1_14_Reincarnation"
## [1] "ATT1_6_IllnessIsImbalance"
## [1] "ATT1_40_StrongerComplaintsMeanHealing"
## [1] "ATT1_29_RadiationTherapyHarmful"
## [1] "ATT1_25_ChemotherapyHarmful"
## [1] "ATT1_39_OnlyNatural"
## [1] "ATT1_22_AvoidPharma"
## [1] "ATT1_37_NoBiopsy"
## [1] "ATT1_30_MandatoryVaccines"
## [1] "ATT1_15_TrustAncientRemedies"
## [1] "ATT1_3_TrustInTradRemedy"
## [1] "ATT1_13_ElectronicRadiation"
## [1] "ATT1_7_HealthyDiet"
## [1] "ATT1_1_ExerciseAndDiet"
## [1] "ATT1_12_WeakImmuneSystem"
## [1] "ATT1_24_IllnessBecauseOfGenes"
## [1] "ATT1_32_TrustWesternDocs"
## [1] "ATT1_35_SeriousSymptom"
## [1] "ATT1_5_DependsOnEnvironment"
## [1] "ATT1_19_DoctorMustHealMe"
## [1] "ATT1_8_NeedTestResult"
### Set labels as names
constructTree$Do(function(node) node$name <-
node$label);
### Convert to DiagrammeR graph
constructGraph <-
data.tree::ToDiagrammeRGraph(constructTree);
### Show graph
DiagrammeR::render_graph(constructGraph);
### Export graph
DiagrammeR::export_graph(constructGraph,
file_name = here::here("methods-construct-tree",
"cam-biomed-attitude-tree-1.png"));
### Also plot as dendrogram (method not exported by this version of data.tree, oddly)
constructDendro <-
data.tree:::as.dendrogram.Node(constructTree);
### Get labels in same order
constructTreeLabels <-
unlist(constructTree$Get('label', filterFun=data.tree::isLeaf));
### For future reference: check
### http://www.sthda.com/english/wiki/beautiful-dendrogram-visualizations-in-r-5-must-known-methods-unsupervised-machine-learning#ggdendro-package-ggplot2-and-dendrogram
ggConstructDendro1 <-
ggdendro::ggdendrogram(constructDendro,
rotate=TRUE,
theme_dendro = TRUE) +
ggplot2::scale_x_continuous(position="top",
breaks=seq_along(constructTreeLabels),
labels=constructTreeLabels) +
ggplot2::scale_y_reverse();
## Scale for 'x' is already present. Adding another scale for 'x', which
## will replace the existing scale.
## Scale for 'y' is already present. Adding another scale for 'y', which
## will replace the existing scale.
print(ggConstructDendro1);
ggsave(filename=here::here("methods-construct-tree",
"cam-biomed-dendrogram-1.png"),
plot=ggConstructDendro1,
width=12,
height=19,
units='cm');
ggConstructDendro2 <-
constructDendro %>%
dendextend::set("branches_k_color",
value = viridis::viridis(4),
k = 4) %>%
dendextend::as.ggdend() %>%
ggplot2::ggplot(horiz=TRUE);
print(ggConstructDendro2);
## Warning: Removed 69 rows containing missing values (geom_point).
ggsave(filename=here::here("methods-construct-tree",
"cam-biomed-dendrogram-2.png"),
plot=ggConstructDendro2,
width=40,
height=30,
units='cm');
## Warning: Removed 69 rows containing missing values (geom_point).
ufs::cat0("\n\n### Group\n\n");
pander(userfriendlyscience::freq(dat$group));
| Frequencies | Perc.Total | Perc.Valid | Cumulative | |
|---|---|---|---|---|
| Alternative medicine | 95 | 60.5 | 60.5 | 60.5 |
| Medicine | 62 | 39.5 | 39.5 | 100 |
| Total valid | 157 | 100 | 100 |
ufs::cat0("\n\n### Missing values\n\n");
apply(is.na(dat[, attitudeVars]), 2, sum);
ATT1_1_ExerciseAndDiet
0
ATT1_2_MustSuffer
0
ATT1_3_TrustInTradRemedy
0
ATT1_4_BodyMirrorToSoul
0
ATT1_5_DependsOnEnvironment
0
ATT1_6_IllnessIsImbalance
0
ATT1_7_HealthyDiet
0
ATT1_8_NeedTestResult
0
ATT1_9_MindHasStrongEffect
0
ATT1_10_AttractPplAndEvents
0
ATT1_11_BodyRemembers
0
ATT1_12_WeakImmuneSystem
0
ATT1_13_ElectronicRadiation
0
ATT1_14_Reincarnation
0
ATT1_15_TrustAncientRemedies
0
ATT1_16_EverythingConnected
0
ATT1_17_SickByChance
0
ATT1_18_TreatsOnlySymptoms
0
ATT1_19_DoctorMustHealMe
0
ATT1_20_HealingIsLuck
0
ATT1_21_IllnessBecauseOfEmotions
0
ATT1_22_AvoidPharma
0
ATT1_23_NothingByChance
0
ATT1_24_IllnessBecauseOfGenes
0
ATT1_25_ChemotherapyHarmful
0
ATT1_26_HealingResultOfEmoDevelopment 0 ATT1_27_EnergeticSystemInBody 0 ATT1_28_ConfrontingEmotionalProb 0 ATT1_29_RadiationTherapyHarmful 0 ATT1_30_MandatoryVaccines 0 ATT1_31_IllnessSymbology 0 ATT1_32_TrustWesternDocs 0 ATT1_33_SymptomsWillDisappear 0 ATT1_34_EnergyInEastern 0 ATT1_35_SeriousSymptom 0 ATT1_36_UnprocessedTrauma 0 ATT1_37_NoBiopsy 3 ATT1_38_IllnessTeachesUs 0 ATT1_39_OnlyNatural 0 ATT1_40_StrongerComplaintsMeanHealing 0
ufs::cat0("\n\n### Attitude\n\n");
ufs::meansComparisonDiamondPlot(dat,
rev(attitudeVars),
compareBy = 'group_tri',
comparisonColors = viridis::viridis(3,
end=.7),
dataAlpha=.25);
### Takes way too long, huge, etc
# GGally::ggpairs(dat[, attitudeVars]);
cors <- cor(dat[, attitudeVars],
use='complete.obs');
knitr::kable(cors);
| ATT1_1_ExerciseAndDiet | ATT1_2_MustSuffer | ATT1_3_TrustInTradRemedy | ATT1_4_BodyMirrorToSoul | ATT1_5_DependsOnEnvironment | ATT1_6_IllnessIsImbalance | ATT1_7_HealthyDiet | ATT1_8_NeedTestResult | ATT1_9_MindHasStrongEffect | ATT1_10_AttractPplAndEvents | ATT1_11_BodyRemembers | ATT1_12_WeakImmuneSystem | ATT1_13_ElectronicRadiation | ATT1_14_Reincarnation | ATT1_15_TrustAncientRemedies | ATT1_16_EverythingConnected | ATT1_17_SickByChance | ATT1_18_TreatsOnlySymptoms | ATT1_19_DoctorMustHealMe | ATT1_20_HealingIsLuck | ATT1_21_IllnessBecauseOfEmotions | ATT1_22_AvoidPharma | ATT1_23_NothingByChance | ATT1_24_IllnessBecauseOfGenes | ATT1_25_ChemotherapyHarmful | ATT1_26_HealingResultOfEmoDevelopment | ATT1_27_EnergeticSystemInBody | ATT1_28_ConfrontingEmotionalProb | ATT1_29_RadiationTherapyHarmful | ATT1_30_MandatoryVaccines | ATT1_31_IllnessSymbology | ATT1_32_TrustWesternDocs | ATT1_33_SymptomsWillDisappear | ATT1_34_EnergyInEastern | ATT1_35_SeriousSymptom | ATT1_36_UnprocessedTrauma | ATT1_37_NoBiopsy | ATT1_38_IllnessTeachesUs | ATT1_39_OnlyNatural | ATT1_40_StrongerComplaintsMeanHealing | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ATT1_1_ExerciseAndDiet | 1.0000000 | 0.0054161 | 0.0687178 | 0.4206610 | -0.0414439 | 0.2658708 | 0.2202788 | -0.0967743 | 0.2122778 | 0.0760936 | 0.1892129 | 0.1034782 | 0.0197600 | 0.0730772 | 0.1222786 | 0.1458379 | 0.0062962 | 0.1090275 | 0.0362593 | -0.1254873 | 0.2249561 | 0.1121921 | 0.1596211 | -0.0164830 | 0.1906475 | 0.2045420 | 0.1596584 | 0.2316194 | 0.1872051 | -0.0340306 | 0.1517998 | -0.0290251 | 0.1898578 | 0.0832831 | -0.1314154 | 0.0743992 | 0.0377949 | 0.1966049 | 0.1688695 | 0.1461166 |
| ATT1_2_MustSuffer | 0.0054161 | 1.0000000 | 0.0399843 | 0.1360426 | 0.3293624 | 0.0756668 | -0.0443301 | 0.0252070 | 0.0776545 | 0.0814977 | 0.0262516 | 0.1212355 | 0.0694189 | -0.0522676 | -0.0062933 | 0.0418795 | 0.1082750 | -0.0678401 | 0.0841814 | -0.0273832 | -0.0240271 | -0.0610453 | 0.0322213 | 0.0786162 | 0.1472411 | 0.0347830 | -0.0862025 | -0.0507096 | 0.1495866 | 0.0462063 | -0.0716466 | -0.0212468 | -0.0415685 | -0.0987391 | 0.0115117 | 0.0925523 | -0.0252680 | -0.0220949 | -0.0304308 | -0.0737804 |
| ATT1_3_TrustInTradRemedy | 0.0687178 | 0.0399843 | 1.0000000 | 0.2249171 | -0.0482545 | 0.2019742 | 0.0566226 | -0.3493843 | 0.3472783 | 0.2674716 | 0.3485551 | -0.0169306 | 0.1413999 | 0.3188806 | 0.4925796 | 0.2322353 | -0.2312852 | 0.3851676 | 0.0061853 | -0.2851330 | 0.2227620 | 0.3985563 | 0.3275579 | -0.2124415 | 0.3874647 | 0.2926369 | 0.3538216 | 0.2801188 | 0.4184651 | 0.2686508 | 0.3136477 | -0.5087061 | 0.1984842 | 0.2455830 | -0.5663668 | 0.2266169 | 0.2334781 | 0.3287663 | 0.4951061 | 0.3783619 |
| ATT1_4_BodyMirrorToSoul | 0.4206610 | 0.1360426 | 0.2249171 | 1.0000000 | 0.2644718 | 0.4779496 | 0.2469704 | -0.1773445 | 0.4429715 | 0.4876800 | 0.5360377 | 0.1440485 | 0.2358389 | 0.2801344 | 0.2823573 | 0.4375893 | -0.0647945 | 0.2574385 | -0.0264387 | -0.1218190 | 0.4357582 | 0.2865663 | 0.4246552 | -0.0219990 | 0.2648194 | 0.4122420 | 0.3586105 | 0.4398906 | 0.3409473 | 0.1974204 | 0.3989796 | -0.1081250 | 0.4612814 | 0.3063318 | -0.2116695 | 0.4052624 | 0.1882564 | 0.3545914 | 0.2240950 | 0.2303519 |
| ATT1_5_DependsOnEnvironment | -0.0414439 | 0.3293624 | -0.0482545 | 0.2644718 | 1.0000000 | 0.1200548 | -0.1975226 | 0.0830335 | 0.2045356 | 0.1821657 | 0.0094967 | 0.1873449 | -0.0446195 | -0.0713644 | -0.0171854 | 0.0381642 | 0.2457939 | -0.1112211 | 0.2337019 | 0.2034428 | 0.1415459 | -0.1093726 | 0.0530034 | 0.2104045 | -0.0806387 | 0.1341475 | 0.0425695 | 0.0881977 | 0.0095487 | 0.1065393 | 0.0068710 | 0.0294318 | 0.1044473 | 0.0123156 | -0.0079130 | 0.0407223 | 0.1606185 | 0.0722145 | -0.0351267 | -0.0293130 |
| ATT1_6_IllnessIsImbalance | 0.2658708 | 0.0756668 | 0.2019742 | 0.4779496 | 0.1200548 | 1.0000000 | 0.2251774 | -0.1567106 | 0.4942181 | 0.3714301 | 0.5247270 | 0.2674479 | 0.2621854 | 0.2540184 | 0.3298663 | 0.4027674 | -0.1979819 | 0.3487299 | -0.0609286 | -0.1203476 | 0.5529565 | 0.3709777 | 0.4331098 | 0.0769675 | 0.3507904 | 0.4152025 | 0.4152410 | 0.4767843 | 0.3305618 | 0.2681004 | 0.5140983 | -0.2432006 | 0.4812476 | 0.3079574 | -0.2762678 | 0.5847060 | 0.1759754 | 0.4818995 | 0.2912395 | 0.2816260 |
| ATT1_7_HealthyDiet | 0.2202788 | -0.0443301 | 0.0566226 | 0.2469704 | -0.1975226 | 0.2251774 | 1.0000000 | -0.0577381 | 0.1661579 | 0.0937240 | 0.2816853 | 0.0937958 | 0.2443342 | 0.1965104 | 0.0586149 | 0.0950937 | -0.1742249 | 0.1239174 | -0.2131927 | -0.0270183 | 0.1236547 | 0.2317797 | 0.1740472 | -0.1791752 | 0.1441873 | 0.1831216 | 0.2162358 | 0.1749697 | 0.1290462 | 0.0485263 | 0.2555365 | -0.0503647 | 0.1477357 | 0.0778997 | -0.1119189 | 0.2489982 | 0.0698320 | 0.2527524 | 0.1982211 | 0.1957129 |
| ATT1_8_NeedTestResult | -0.0967743 | 0.0252070 | -0.3493843 | -0.1773445 | 0.0830335 | -0.1567106 | -0.0577381 | 1.0000000 | -0.0520796 | -0.1485616 | -0.1486377 | 0.0247272 | -0.0167402 | -0.1849931 | -0.2613940 | -0.1658542 | 0.0969698 | -0.2789160 | 0.2018276 | 0.1247677 | -0.1018884 | -0.2362467 | -0.2229017 | 0.1715445 | -0.2803159 | -0.1360690 | -0.2433245 | -0.2243612 | -0.2923480 | -0.1034996 | -0.2434594 | 0.3172283 | -0.1670566 | -0.1592532 | 0.4402867 | -0.0444246 | -0.0619809 | -0.1714422 | -0.2775466 | -0.1582221 |
| ATT1_9_MindHasStrongEffect | 0.2122778 | 0.0776545 | 0.3472783 | 0.4429715 | 0.2045356 | 0.4942181 | 0.1661579 | -0.0520796 | 1.0000000 | 0.5022850 | 0.5206856 | 0.1789726 | 0.2818216 | 0.4038429 | 0.3913952 | 0.4459452 | -0.2293779 | 0.3244870 | -0.0896558 | -0.0758399 | 0.5388819 | 0.3928680 | 0.5244709 | 0.0436545 | 0.3016080 | 0.4885815 | 0.4698365 | 0.5385189 | 0.3117382 | 0.2482769 | 0.4417475 | -0.2520904 | 0.4397829 | 0.3413725 | -0.3279419 | 0.4854531 | 0.2312013 | 0.4841892 | 0.2979948 | 0.3670536 |
| ATT1_10_AttractPplAndEvents | 0.0760936 | 0.0814977 | 0.2674716 | 0.4876800 | 0.1821657 | 0.3714301 | 0.0937240 | -0.1485616 | 0.5022850 | 1.0000000 | 0.5235645 | 0.0993749 | 0.3326897 | 0.4626649 | 0.3811754 | 0.6130047 | -0.2588225 | 0.3476191 | -0.0997466 | -0.1291992 | 0.4452941 | 0.2820609 | 0.5811317 | -0.1367010 | 0.2825817 | 0.4091527 | 0.5430469 | 0.4736931 | 0.3240820 | 0.1639470 | 0.5365687 | -0.2417653 | 0.3960050 | 0.4959991 | -0.2776490 | 0.4367480 | 0.1414104 | 0.4262265 | 0.2030081 | 0.2852613 |
| ATT1_11_BodyRemembers | 0.1892129 | 0.0262516 | 0.3485551 | 0.5360377 | 0.0094967 | 0.5247270 | 0.2816853 | -0.1486377 | 0.5206856 | 0.5235645 | 1.0000000 | 0.1312519 | 0.4138740 | 0.4764432 | 0.4066875 | 0.5147970 | -0.2925920 | 0.3803597 | -0.1579940 | -0.1256117 | 0.4898779 | 0.4032909 | 0.5287270 | -0.0610542 | 0.3346039 | 0.4876131 | 0.6052014 | 0.5692964 | 0.3485249 | 0.3349171 | 0.6052088 | -0.1897516 | 0.5295881 | 0.4972222 | -0.3124592 | 0.5754526 | 0.2825870 | 0.5686156 | 0.3657404 | 0.3253450 |
| ATT1_12_WeakImmuneSystem | 0.1034782 | 0.1212355 | -0.0169306 | 0.1440485 | 0.1873449 | 0.2674479 | 0.0937958 | 0.0247272 | 0.1789726 | 0.0993749 | 0.1312519 | 1.0000000 | 0.2752603 | 0.0479077 | 0.0835712 | 0.0297011 | -0.0034640 | -0.0055184 | 0.2857657 | -0.0617796 | 0.3200732 | 0.1321390 | 0.0471601 | 0.3381754 | 0.1719405 | 0.1731542 | 0.0834863 | 0.2514190 | 0.2075617 | 0.0926864 | 0.1847677 | 0.1109876 | 0.2273381 | -0.0116188 | -0.0983390 | 0.1690157 | -0.0084918 | 0.2326579 | 0.0926467 | 0.0946424 |
| ATT1_13_ElectronicRadiation | 0.0197600 | 0.0694189 | 0.1413999 | 0.2358389 | -0.0446195 | 0.2621854 | 0.2443342 | -0.0167402 | 0.2818216 | 0.3326897 | 0.4138740 | 0.2752603 | 1.0000000 | 0.3555378 | 0.3075953 | 0.3902444 | -0.0504260 | 0.1899664 | -0.1472693 | 0.0383195 | 0.3629332 | 0.3639161 | 0.3729933 | 0.0443294 | 0.2510667 | 0.3453951 | 0.4484465 | 0.4734375 | 0.2937201 | 0.2040601 | 0.4658634 | -0.1298798 | 0.2325318 | 0.3497912 | -0.2163133 | 0.4491260 | 0.1815445 | 0.4567256 | 0.2382258 | 0.2388390 |
| ATT1_14_Reincarnation | 0.0730772 | -0.0522676 | 0.3188806 | 0.2801344 | -0.0713644 | 0.2540184 | 0.1965104 | -0.1849931 | 0.4038429 | 0.4626649 | 0.4764432 | 0.0479077 | 0.3555378 | 1.0000000 | 0.4727992 | 0.4949819 | -0.3822183 | 0.3720714 | -0.2446042 | -0.0097380 | 0.3700497 | 0.4332687 | 0.5763142 | -0.1813892 | 0.3351660 | 0.4559591 | 0.6405835 | 0.5220288 | 0.3426169 | 0.1475878 | 0.5489846 | -0.2995215 | 0.3574128 | 0.4116090 | -0.3735119 | 0.4033991 | 0.2505121 | 0.5153787 | 0.4316867 | 0.4462609 |
| ATT1_15_TrustAncientRemedies | 0.1222786 | -0.0062933 | 0.4925796 | 0.2823573 | -0.0171854 | 0.3298663 | 0.0586149 | -0.2613940 | 0.3913952 | 0.3811754 | 0.4066875 | 0.0835712 | 0.3075953 | 0.4727992 | 1.0000000 | 0.3855192 | -0.1294319 | 0.5828173 | 0.0266763 | -0.0932796 | 0.3212942 | 0.5331970 | 0.4771336 | -0.0234370 | 0.4961676 | 0.4796036 | 0.5500308 | 0.5508476 | 0.5334350 | 0.1872026 | 0.4559673 | -0.5413175 | 0.3699070 | 0.4266635 | -0.5217664 | 0.3437206 | 0.4094316 | 0.5057373 | 0.5679982 | 0.4669802 |
| ATT1_16_EverythingConnected | 0.1458379 | 0.0418795 | 0.2322353 | 0.4375893 | 0.0381642 | 0.4027674 | 0.0950937 | -0.1658542 | 0.4459452 | 0.6130047 | 0.5147970 | 0.0297011 | 0.3902444 | 0.4949819 | 0.3855192 | 1.0000000 | -0.2424026 | 0.3139141 | -0.2041912 | -0.1176678 | 0.4198273 | 0.3257879 | 0.6619870 | -0.1473315 | 0.2552401 | 0.3279818 | 0.5174101 | 0.4652473 | 0.2701384 | 0.2323531 | 0.5316003 | -0.1862762 | 0.4002202 | 0.4271042 | -0.2537242 | 0.4837864 | 0.1709845 | 0.4959438 | 0.2240387 | 0.2465442 |
| ATT1_17_SickByChance | 0.0062962 | 0.1082750 | -0.2312852 | -0.0647945 | 0.2457939 | -0.1979819 | -0.1742249 | 0.0969698 | -0.2293779 | -0.2588225 | -0.2925920 | -0.0034640 | -0.0504260 | -0.3822183 | -0.1294319 | -0.2424026 | 1.0000000 | -0.0547868 | 0.2497055 | 0.2709308 | -0.1708978 | -0.1182007 | -0.2521696 | 0.2942955 | -0.0583775 | -0.0383939 | -0.1873298 | -0.0814155 | -0.0474106 | -0.2829891 | -0.3211128 | 0.2435520 | -0.1002422 | -0.0726241 | 0.1893255 | -0.2876047 | -0.0235375 | -0.1934261 | -0.1167337 | -0.0729482 |
| ATT1_18_TreatsOnlySymptoms | 0.1090275 | -0.0678401 | 0.3851676 | 0.2574385 | -0.1112211 | 0.3487299 | 0.1239174 | -0.2789160 | 0.3244870 | 0.3476191 | 0.3803597 | -0.0055184 | 0.1899664 | 0.3720714 | 0.5828173 | 0.3139141 | -0.0547868 | 1.0000000 | -0.0509052 | -0.0661100 | 0.3849268 | 0.4861793 | 0.4526995 | -0.0914244 | 0.5365594 | 0.4514097 | 0.5846754 | 0.4430940 | 0.4434167 | 0.1410178 | 0.4160762 | -0.5366664 | 0.4022170 | 0.3760035 | -0.4209134 | 0.2675946 | 0.3751284 | 0.4160301 | 0.4353256 | 0.3681333 |
| ATT1_19_DoctorMustHealMe | 0.0362593 | 0.0841814 | 0.0061853 | -0.0264387 | 0.2337019 | -0.0609286 | -0.2131927 | 0.2018276 | -0.0896558 | -0.0997466 | -0.1579940 | 0.2857657 | -0.1472693 | -0.2446042 | 0.0266763 | -0.2041912 | 0.2497055 | -0.0509052 | 1.0000000 | 0.1102324 | -0.0046624 | -0.0665886 | -0.2321891 | 0.3033737 | 0.0750817 | 0.0334014 | -0.1645822 | -0.0908550 | 0.1426962 | -0.1049117 | -0.1679975 | 0.0919329 | -0.0536017 | -0.1017156 | 0.0349323 | -0.1275742 | 0.0517993 | -0.0990084 | 0.0563547 | -0.1921637 |
| ATT1_20_HealingIsLuck | -0.1254873 | -0.0273832 | -0.2851330 | -0.1218190 | 0.2034428 | -0.1203476 | -0.0270183 | 0.1247677 | -0.0758399 | -0.1291992 | -0.1256117 | -0.0617796 | 0.0383195 | -0.0097380 | -0.0932796 | -0.1176678 | 0.2709308 | -0.0661100 | 0.1102324 | 1.0000000 | -0.0613623 | -0.1051493 | 0.0239701 | 0.1910189 | -0.1271732 | 0.1051900 | 0.0429204 | -0.0055617 | -0.1255844 | -0.1137934 | -0.0714842 | 0.1369722 | 0.0012417 | -0.0746562 | 0.2071352 | -0.0280356 | 0.2436418 | 0.0034805 | -0.0795954 | -0.0577502 |
| ATT1_21_IllnessBecauseOfEmotions | 0.2249561 | -0.0240271 | 0.2227620 | 0.4357582 | 0.1415459 | 0.5529565 | 0.1236547 | -0.1018884 | 0.5388819 | 0.4452941 | 0.4898779 | 0.3200732 | 0.3629332 | 0.3700497 | 0.3212942 | 0.4198273 | -0.1708978 | 0.3849268 | -0.0046624 | -0.0613623 | 1.0000000 | 0.3456913 | 0.4929943 | 0.1545845 | 0.3394108 | 0.6272069 | 0.5051314 | 0.6357904 | 0.3311708 | 0.2190891 | 0.6680852 | -0.1926746 | 0.6436437 | 0.4242667 | -0.1779632 | 0.5839249 | 0.2156674 | 0.5067599 | 0.2591468 | 0.3053829 |
| ATT1_22_AvoidPharma | 0.1121921 | -0.0610453 | 0.3985563 | 0.2865663 | -0.1093726 | 0.3709777 | 0.2317797 | -0.2362467 | 0.3928680 | 0.2820609 | 0.4032909 | 0.1321390 | 0.3639161 | 0.4332687 | 0.5331970 | 0.3257879 | -0.1182007 | 0.4861793 | -0.0665886 | -0.1051493 | 0.3456913 | 1.0000000 | 0.4738300 | -0.0700838 | 0.4079969 | 0.4069011 | 0.4521505 | 0.4431287 | 0.4472165 | 0.2537590 | 0.4735388 | -0.4527800 | 0.3351502 | 0.2885399 | -0.5089255 | 0.4088550 | 0.2789144 | 0.4196286 | 0.5995711 | 0.4623255 |
| ATT1_23_NothingByChance | 0.1596211 | 0.0322213 | 0.3275579 | 0.4246552 | 0.0530034 | 0.4331098 | 0.1740472 | -0.2229017 | 0.5244709 | 0.5811317 | 0.5287270 | 0.0471601 | 0.3729933 | 0.5763142 | 0.4771336 | 0.6619870 | -0.2521696 | 0.4526995 | -0.2321891 | 0.0239701 | 0.4929943 | 0.4738300 | 1.0000000 | 0.0109790 | 0.3681791 | 0.5088340 | 0.5826668 | 0.5841888 | 0.4133183 | 0.1754654 | 0.6537926 | -0.2934296 | 0.4506522 | 0.3769215 | -0.3170201 | 0.4871373 | 0.2807297 | 0.6780911 | 0.3021821 | 0.4063435 |
| ATT1_24_IllnessBecauseOfGenes | -0.0164830 | 0.0786162 | -0.2124415 | -0.0219990 | 0.2104045 | 0.0769675 | -0.1791752 | 0.1715445 | 0.0436545 | -0.1367010 | -0.0610542 | 0.3381754 | 0.0443294 | -0.1813892 | -0.0234370 | -0.1473315 | 0.2942955 | -0.0914244 | 0.3033737 | 0.1910189 | 0.1545845 | -0.0700838 | 0.0109790 | 1.0000000 | -0.0270229 | 0.2135496 | -0.1242561 | 0.0472935 | -0.0074568 | 0.0309905 | -0.0371198 | 0.1354120 | 0.0457838 | -0.1547928 | 0.1830111 | 0.0267491 | 0.0755117 | -0.0103802 | -0.1452718 | -0.1160408 |
| ATT1_25_ChemotherapyHarmful | 0.1906475 | 0.1472411 | 0.3874647 | 0.2648194 | -0.0806387 | 0.3507904 | 0.1441873 | -0.2803159 | 0.3016080 | 0.2825817 | 0.3346039 | 0.1719405 | 0.2510667 | 0.3351660 | 0.4961676 | 0.2552401 | -0.0583775 | 0.5365594 | 0.0750817 | -0.1271732 | 0.3394108 | 0.4079969 | 0.3681791 | -0.0270229 | 1.0000000 | 0.4546396 | 0.4015689 | 0.4160576 | 0.8428863 | 0.1613083 | 0.3700511 | -0.3874451 | 0.3426574 | 0.1531717 | -0.3829592 | 0.3390217 | 0.2844477 | 0.3859409 | 0.4599611 | 0.3060069 |
| ATT1_26_HealingResultOfEmoDevelopment | 0.2045420 | 0.0347830 | 0.2926369 | 0.4122420 | 0.1341475 | 0.4152025 | 0.1831216 | -0.1360690 | 0.4885815 | 0.4091527 | 0.4876131 | 0.1731542 | 0.3453951 | 0.4559591 | 0.4796036 | 0.3279818 | -0.0383939 | 0.4514097 | 0.0334014 | 0.1051900 | 0.6272069 | 0.4069011 | 0.5088340 | 0.2135496 | 0.4546396 | 1.0000000 | 0.5238756 | 0.6860565 | 0.4238871 | 0.2454408 | 0.6083206 | -0.2645614 | 0.6146357 | 0.4278928 | -0.3004552 | 0.4424484 | 0.3652104 | 0.6161122 | 0.3447994 | 0.3893012 |
| ATT1_27_EnergeticSystemInBody | 0.1596584 | -0.0862025 | 0.3538216 | 0.3586105 | 0.0425695 | 0.4152410 | 0.2162358 | -0.2433245 | 0.4698365 | 0.5430469 | 0.6052014 | 0.0834863 | 0.4484465 | 0.6405835 | 0.5500308 | 0.5174101 | -0.1873298 | 0.5846754 | -0.1645822 | 0.0429204 | 0.5051314 | 0.4521505 | 0.5826668 | -0.1242561 | 0.4015689 | 0.5238756 | 1.0000000 | 0.7000795 | 0.3820224 | 0.2271138 | 0.6132902 | -0.3120822 | 0.5348839 | 0.6521425 | -0.4546381 | 0.5079048 | 0.4149599 | 0.6549123 | 0.4553830 | 0.4556764 |
| ATT1_28_ConfrontingEmotionalProb | 0.2316194 | -0.0507096 | 0.2801188 | 0.4398906 | 0.0881977 | 0.4767843 | 0.1749697 | -0.2243612 | 0.5385189 | 0.4736931 | 0.5692964 | 0.2514190 | 0.4734375 | 0.5220288 | 0.5508476 | 0.4652473 | -0.0814155 | 0.4430940 | -0.0908550 | -0.0055617 | 0.6357904 | 0.4431287 | 0.5841888 | 0.0472935 | 0.4160576 | 0.6860565 | 0.7000795 | 1.0000000 | 0.4046572 | 0.2143869 | 0.6510185 | -0.2109775 | 0.7099183 | 0.5365014 | -0.3740117 | 0.5366858 | 0.3231583 | 0.6910299 | 0.3852736 | 0.4165323 |
| ATT1_29_RadiationTherapyHarmful | 0.1872051 | 0.1495866 | 0.4184651 | 0.3409473 | 0.0095487 | 0.3305618 | 0.1290462 | -0.2923480 | 0.3117382 | 0.3240820 | 0.3485249 | 0.2075617 | 0.2937201 | 0.3426169 | 0.5334350 | 0.2701384 | -0.0474106 | 0.4434167 | 0.1426962 | -0.1255844 | 0.3311708 | 0.4472165 | 0.4133183 | -0.0074568 | 0.8428863 | 0.4238871 | 0.3820224 | 0.4046572 | 1.0000000 | 0.1547363 | 0.3815457 | -0.3602146 | 0.3113579 | 0.1294614 | -0.4278274 | 0.3487336 | 0.2931028 | 0.4152680 | 0.5058298 | 0.3417558 |
| ATT1_30_MandatoryVaccines | -0.0340306 | 0.0462063 | 0.2686508 | 0.1974204 | 0.1065393 | 0.2681004 | 0.0485263 | -0.1034996 | 0.2482769 | 0.1639470 | 0.3349171 | 0.0926864 | 0.2040601 | 0.1475878 | 0.1872026 | 0.2323531 | -0.2829891 | 0.1410178 | -0.1049117 | -0.1137934 | 0.2190891 | 0.2537590 | 0.1754654 | 0.0309905 | 0.1613083 | 0.2454408 | 0.2271138 | 0.2143869 | 0.1547363 | 1.0000000 | 0.1954700 | -0.3064897 | 0.1714389 | 0.0793773 | -0.2846922 | 0.2840609 | 0.3333933 | 0.2076523 | 0.2054123 | 0.1289035 |
| ATT1_31_IllnessSymbology | 0.1517998 | -0.0716466 | 0.3136477 | 0.3989796 | 0.0068710 | 0.5140983 | 0.2555365 | -0.2434594 | 0.4417475 | 0.5365687 | 0.6052088 | 0.1847677 | 0.4658634 | 0.5489846 | 0.4559673 | 0.5316003 | -0.3211128 | 0.4160762 | -0.1679975 | -0.0714842 | 0.6680852 | 0.4735388 | 0.6537926 | -0.0371198 | 0.3700511 | 0.6083206 | 0.6132902 | 0.6510185 | 0.3815457 | 0.1954700 | 1.0000000 | -0.2869571 | 0.5645111 | 0.4660545 | -0.3801909 | 0.5500127 | 0.1790779 | 0.6952910 | 0.4007775 | 0.4305977 |
| ATT1_32_TrustWesternDocs | -0.0290251 | -0.0212468 | -0.5087061 | -0.1081250 | 0.0294318 | -0.2432006 | -0.0503647 | 0.3172283 | -0.2520904 | -0.2417653 | -0.1897516 | 0.1109876 | -0.1298798 | -0.2995215 | -0.5413175 | -0.1862762 | 0.2435520 | -0.5366664 | 0.0919329 | 0.1369722 | -0.1926746 | -0.4527800 | -0.2934296 | 0.1354120 | -0.3874451 | -0.2645614 | -0.3120822 | -0.2109775 | -0.3602146 | -0.3064897 | -0.2869571 | 1.0000000 | -0.0889459 | -0.1661708 | 0.5801770 | -0.1927122 | -0.3233230 | -0.2108713 | -0.4836589 | -0.1966027 |
| ATT1_33_SymptomsWillDisappear | 0.1898578 | -0.0415685 | 0.1984842 | 0.4612814 | 0.1044473 | 0.4812476 | 0.1477357 | -0.1670566 | 0.4397829 | 0.3960050 | 0.5295881 | 0.2273381 | 0.2325318 | 0.3574128 | 0.3699070 | 0.4002202 | -0.1002422 | 0.4022170 | -0.0536017 | 0.0012417 | 0.6436437 | 0.3351502 | 0.4506522 | 0.0457838 | 0.3426574 | 0.6146357 | 0.5348839 | 0.7099183 | 0.3113579 | 0.1714389 | 0.5645111 | -0.0889459 | 1.0000000 | 0.4559997 | -0.2067542 | 0.5295790 | 0.2502046 | 0.6034346 | 0.3033756 | 0.3195752 |
| ATT1_34_EnergyInEastern | 0.0832831 | -0.0987391 | 0.2455830 | 0.3063318 | 0.0123156 | 0.3079574 | 0.0778997 | -0.1592532 | 0.3413725 | 0.4959991 | 0.4972222 | -0.0116188 | 0.3497912 | 0.4116090 | 0.4266635 | 0.4271042 | -0.0726241 | 0.3760035 | -0.1017156 | -0.0746562 | 0.4242667 | 0.2885399 | 0.3769215 | -0.1547928 | 0.1531717 | 0.4278928 | 0.6521425 | 0.5365014 | 0.1294614 | 0.0793773 | 0.4660545 | -0.1661708 | 0.4559997 | 1.0000000 | -0.2287806 | 0.3951118 | 0.1294561 | 0.4327702 | 0.2773837 | 0.2903717 |
| ATT1_35_SeriousSymptom | -0.1314154 | 0.0115117 | -0.5663668 | -0.2116695 | -0.0079130 | -0.2762678 | -0.1119189 | 0.4402867 | -0.3279419 | -0.2776490 | -0.3124592 | -0.0983390 | -0.2163133 | -0.3735119 | -0.5217664 | -0.2537242 | 0.1893255 | -0.4209134 | 0.0349323 | 0.2071352 | -0.1779632 | -0.5089255 | -0.3170201 | 0.1830111 | -0.3829592 | -0.3004552 | -0.4546381 | -0.3740117 | -0.4278274 | -0.2846922 | -0.3801909 | 0.5801770 | -0.2067542 | -0.2287806 | 1.0000000 | -0.1848200 | -0.2706797 | -0.3907500 | -0.6067400 | -0.4759387 |
| ATT1_36_UnprocessedTrauma | 0.0743992 | 0.0925523 | 0.2266169 | 0.4052624 | 0.0407223 | 0.5847060 | 0.2489982 | -0.0444246 | 0.4854531 | 0.4367480 | 0.5754526 | 0.1690157 | 0.4491260 | 0.4033991 | 0.3437206 | 0.4837864 | -0.2876047 | 0.2675946 | -0.1275742 | -0.0280356 | 0.5839249 | 0.4088550 | 0.4871373 | 0.0267491 | 0.3390217 | 0.4424484 | 0.5079048 | 0.5366858 | 0.3487336 | 0.2840609 | 0.5500127 | -0.1927122 | 0.5295790 | 0.3951118 | -0.1848200 | 1.0000000 | 0.1900231 | 0.5531866 | 0.3412182 | 0.3970854 |
| ATT1_37_NoBiopsy | 0.0377949 | -0.0252680 | 0.2334781 | 0.1882564 | 0.1606185 | 0.1759754 | 0.0698320 | -0.0619809 | 0.2312013 | 0.1414104 | 0.2825870 | -0.0084918 | 0.1815445 | 0.2505121 | 0.4094316 | 0.1709845 | -0.0235375 | 0.3751284 | 0.0517993 | 0.2436418 | 0.2156674 | 0.2789144 | 0.2807297 | 0.0755117 | 0.2844477 | 0.3652104 | 0.4149599 | 0.3231583 | 0.2931028 | 0.3333933 | 0.1790779 | -0.3233230 | 0.2502046 | 0.1294561 | -0.2706797 | 0.1900231 | 1.0000000 | 0.4094720 | 0.2964953 | 0.1801603 |
| ATT1_38_IllnessTeachesUs | 0.1966049 | -0.0220949 | 0.3287663 | 0.3545914 | 0.0722145 | 0.4818995 | 0.2527524 | -0.1714422 | 0.4841892 | 0.4262265 | 0.5686156 | 0.2326579 | 0.4567256 | 0.5153787 | 0.5057373 | 0.4959438 | -0.1934261 | 0.4160301 | -0.0990084 | 0.0034805 | 0.5067599 | 0.4196286 | 0.6780911 | -0.0103802 | 0.3859409 | 0.6161122 | 0.6549123 | 0.6910299 | 0.4152680 | 0.2076523 | 0.6952910 | -0.2108713 | 0.6034346 | 0.4327702 | -0.3907500 | 0.5531866 | 0.4094720 | 1.0000000 | 0.3786605 | 0.5594566 |
| ATT1_39_OnlyNatural | 0.1688695 | -0.0304308 | 0.4951061 | 0.2240950 | -0.0351267 | 0.2912395 | 0.1982211 | -0.2775466 | 0.2979948 | 0.2030081 | 0.3657404 | 0.0926467 | 0.2382258 | 0.4316867 | 0.5679982 | 0.2240387 | -0.1167337 | 0.4353256 | 0.0563547 | -0.0795954 | 0.2591468 | 0.5995711 | 0.3021821 | -0.1452718 | 0.4599611 | 0.3447994 | 0.4553830 | 0.3852736 | 0.5058298 | 0.2054123 | 0.4007775 | -0.4836589 | 0.3033756 | 0.2773837 | -0.6067400 | 0.3412182 | 0.2964953 | 0.3786605 | 1.0000000 | 0.5112160 |
| ATT1_40_StrongerComplaintsMeanHealing | 0.1461166 | -0.0737804 | 0.3783619 | 0.2303519 | -0.0293130 | 0.2816260 | 0.1957129 | -0.1582221 | 0.3670536 | 0.2852613 | 0.3253450 | 0.0946424 | 0.2388390 | 0.4462609 | 0.4669802 | 0.2465442 | -0.0729482 | 0.3681333 | -0.1921637 | -0.0577502 | 0.3053829 | 0.4623255 | 0.4063435 | -0.1160408 | 0.3060069 | 0.3893012 | 0.4556764 | 0.4165323 | 0.3417558 | 0.1289035 | 0.4305977 | -0.1966027 | 0.3195752 | 0.2903717 | -0.4759387 | 0.3970854 | 0.1801603 | 0.5594566 | 0.5112160 | 1.0000000 |
### Save to csv
write.csv(cors,
file=file.path(workingPath,
"correlations--bivariate--all-cases.csv"));
### http://www.sthda.com/english/wiki/ggcorrplot-visualization-of-a-correlation-matrix-using-ggplot2
ggcorrplot::ggcorrplot(cors);
ggcorrplot::ggcorrplot(cors,
method = "circle");
ggcorrplot(cors,
hc.order = TRUE,
outline.col = "white")
ggcorrplot::ggcorrplot(cors,
lab = TRUE);
for (xAxisVar in attitudeVars) {
ufs::cat0("\n\n#### ", xAxisVar,
" {.tabset .tabset-fade .tabset-pills}\n\n");
for (yAxisVar in tail(attitudeVars, -1)) {
### Only for 'half the matrix'
if (which(attitudeVars == yAxisVar) >
which(attitudeVars == xAxisVar)) {
ufs::cat0("\n\n##### ", yAxisVar,
"\n\n");
print(ggplot2::ggplot(data=dat,
mapping=ggplot2::aes_string(x=xAxisVar,
y=yAxisVar,
color='group_tri')) +
geom_jitter(size=3) +
theme_minimal());
}
}
}
For the network analysis section we will first estimate a full network where a choice of medical practice is regarded as a system component. This will allow us to explore how attitudes relate to the behavior of interest and the relative importance of each determinant. Afterwards, we will create sub samples based on a variable that represents groups of people that prefere one or other medical practice. This way we can investigate structural features of networks (topologies) that are peculiar to these groups.
# here I subset data that is going to be used in the network analysis with the behavior as a component.
subset <- dat[, c(attitudeVars,
"group_tri")];
# I eliminated other variables of interest (sex, age etc.) because the N in subgroups are very small and the number of "predictor" variables would exceed the number of datapoints.
### Here I create subsets based on the grouping variable.
for(i in levels(subset$group_tri)){
assign(paste("subset",
i,
sep = "_"),
subset(subset,
subset$group_tri == i))
}
subset$group_tri <-
as.numeric(subset$group_tri);
subset <-
subset %>% tidyr::drop_na();
network <-
estimateNetwork(subset,
default = "EBICglasso");
## Estimating Network. Using package::function:
## - qgraph::EBICglasso for EBIC model selection
## - using glasso::glasso
## - qgraph::cor_auto for correlation computation
## - using lavaan::lavCor
## Variables detected as ordinal: ATT1_1_ExerciseAndDiet; ATT1_2_MustSuffer; ATT1_3_TrustInTradRemedy; ATT1_4_BodyMirrorToSoul; ATT1_5_DependsOnEnvironment; ATT1_6_IllnessIsImbalance; ATT1_7_HealthyDiet; ATT1_8_NeedTestResult; ATT1_9_MindHasStrongEffect; ATT1_10_AttractPplAndEvents; ATT1_11_BodyRemembers; ATT1_12_WeakImmuneSystem; ATT1_13_ElectronicRadiation; ATT1_14_Reincarnation; ATT1_15_TrustAncientRemedies; ATT1_16_EverythingConnected; ATT1_17_SickByChance; ATT1_18_TreatsOnlySymptoms; ATT1_19_DoctorMustHealMe; ATT1_20_HealingIsLuck; ATT1_21_IllnessBecauseOfEmotions; ATT1_22_AvoidPharma; ATT1_23_NothingByChance; ATT1_24_IllnessBecauseOfGenes; ATT1_25_ChemotherapyHarmful; ATT1_26_HealingResultOfEmoDevelopment; ATT1_27_EnergeticSystemInBody; ATT1_28_ConfrontingEmotionalProb; ATT1_29_RadiationTherapyHarmful; ATT1_30_MandatoryVaccines; ATT1_31_IllnessSymbology; ATT1_32_TrustWesternDocs; ATT1_33_SymptomsWillDisappear; ATT1_34_EnergyInEastern; ATT1_35_SeriousSymptom; ATT1_36_UnprocessedTrauma; ATT1_37_NoBiopsy; ATT1_38_IllnessTeachesUs; ATT1_39_OnlyNatural; ATT1_40_StrongerComplaintsMeanHealing; group_tri
plot(network,
layout = 'spring',
labels = colnames(network),
title = c('Figure 1: A Network with the behavioral variable'));
### Also store to disk - Sam, you can copy this for any other plots of course
pdf(here::here('results-intermediate',
'network-with-grouping-variable.pdf'));
plot(network,
layout = 'spring',
labels = colnames(network),
title = c('Figure 1: A Network with the behavioral variable'));
dev.off();
png 2
# Calculating centrality measures.
pdf(here::here('results-intermediate',
'centrality_plot.pdf'));
centralityPlot(network,
include = "all");
## Note: z-scores are shown on x-axis rather than raw centrality indices.
dev.off();
png 2
# # Checking the stability of the centrality measures
# central_stability <-
# bootnet(network,
# nCores = 20,
# nBoots = 1000,
# type = 'case');
#
# pdf(here::here('results-intermediate',
# 'centrality_stability_plot.pdf'));
# plot(central_stability)
# dev.off();
#
# # Checking the stability/reliability of the edge weights
# edgewgt <-
# bootnet(network,
# nCores = 20,
# nBoots = 2500);
#
# plot(edgewgt,
# labels = FALSE,
# order = 'sample');
#
# pdf(here::here('results-intermediate',
# 'edge_weights.pdf'));
# plot(edgewgt,
# labels = FALSE,
# order = 'sample');
# dev.off();
Before applying Dijkstra’s algorithm we need to 1/the corelation matrix to invert it so the strongest connections will be represented with smaller numbers and the smallest correlations with larger.
### First we need to take the absoulte values of the adjacency matrix and devide 1 by the matrix. Then recreate a network object for further analysis.
absolute_adj <-
abs(network$graph);
for (i in which(absolute_adj > 0)) {
absolute_adj[i] = 1/absolute_adj[i]
}
graph_full <-
graph.adjacency(absolute_adj,
mode = 'undirected',
weighted = TRUE);
# Calculate shortest path to the outcome variable and then delete the last row of the dataframe that includes the outcome variable (shortest path to itself = 0)
dijkstra_fullnetwork <-
igraph::distances(graph_full,
v = V(graph_full),
to = 41,
algorithm = "dijkstra");
dijkstra_ful <-
subset(dijkstra_fullnetwork,
dijkstra_fullnetwork[,] == min(dijkstra_fullnetwork[-c(41),]));
Here we apply greedy hirarchical clustering algorithm to detect clusters in the data. Then we plot the results and the respective dendrogram.
fg <-
fastgreedy.community(graph_full, weights = E(graph_full)$weight)
fg$names <-
strtrim(fg$names, 7)
V(graph_full)$name <-
strtrim(fg$names, 7)
length(fg)
[1] 6
sizes(fg)
Community sizes 1 2 3 4 5 6 16 6 9 3 4 3
set.seed(100)
par(mfrow=c(1,2))
plot(fg, graph_full,
vertex.label.cex=c(0.5,0.5,0.5),
vertex.label.font=c(2))
dendPlot(fg, mode = 'phylo')
alternative <-
tidyr::drop_na(subset_Alternative[,-c(41)])
biomedical <-
tidyr::drop_na(subset_Biomed[,-c(41)])
network_fgl <-
EstimateGroupNetwork(list('Alternative' = alternative,
"Biomed" = biomedical)) # We get an empty network.
absolute_adj_hc <-
abs(network$graph);
graph_full_hc <-
graph.adjacency(absolute_adj[-c(41),-c(41)],
mode = 'undirected',
weighted = TRUE)
fg_item <-
fastgreedy.community(graph_full_hc, weights = E(graph_full_hc)$weight)
fg_item$names <-
strtrim(fg_item$names, 7)
V(graph_full_hc)$name <-
strtrim(fg_item$names, 7)
length(fg_item)
[1] 6
sizes(fg_item)
Community sizes 1 2 3 4 5 6 14 11 3 5 4 3
set.seed(101)
par(mfrow=c(1,2))
plot(fg_item, graph_full_hc,
vertex.label.cex=c(0.5,0.5,0.5),
vertex.label.font=c(2))
dendPlot(fg_item, mode = 'phylo')